import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-05-21
 * Time: 15:27
 */
public class test2 {
    public int[] sortArray(int[] nums) {
        qsort(nums,0,nums.length-1);
        return nums;
    }

    private void qsort(int[] nums, int l, int r) {
        if(l>=r){
            return;
        }
        int left = l-1;
        int right = r+1;
        int i=l;
        // 随机产生一个用于比较的key
        int key = nums[new Random().nextInt(r-l+1)+l];
        while(i<right){
            if(nums[i]<key){
                swap(nums,++left,i++);
            } else if (nums[i]==key) {
                i++;
            }else {
                swap(nums,--right,i);
            }
        }

        qsort(nums,l,left);
        qsort(nums,right,r);
    }

    private void swap(int[] nums, int left, int right) {
        int tmp = nums[left];
        nums[left] = nums[right];
        nums[right] = tmp;
    }

}
